﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.Logging;
using WuDada.Core.Member;
using WuDada.Core.Member.Service;
using WuDada.Core.Member.Domain;
using WuDada.Core.Generic.Util;
using WuDada.Core.SystemApplications.Domain;

public partial class forget : System.Web.UI.Page
{
    private ILog m_Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private MemberFactory m_MemberFactory;
    private IMemberService m_MemberService;
    private HttpHelper m_HttpHelper;
    private WebMailService m_WebMailService;
    private SessionHelper m_SessionHelper = new SessionHelper();
    private string memberPath = "member.aspx";

    protected void Page_Load(object sender, EventArgs e)
    {
        m_MemberFactory = new MemberFactory();
        m_MemberService = m_MemberFactory.GetMemberService();
        m_HttpHelper = new HttpHelper();
        m_WebMailService = new WebMailService();

        if (!Page.IsPostBack)
        {
            if (m_SessionHelper.Member != null)
            {
                Response.Redirect(memberPath);
            }
        }
    }

    protected void btnSendPassword_Click(object sender, EventArgs e)
    {
        string account = txtAccount.Text.Trim();
        MemberVO memberVO = m_MemberService.GetMemberByLoginId(account);
        if (memberVO != null && "1".Equals(memberVO.Status) && "1".Equals(memberVO.UserConfirm))
        {
            //發信
            m_WebMailService.SendForgetPassMail_ToMember(memberVO);
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJSAndRedirect("已寄出新密碼!", "login.aspx"), false);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("帳號不存在或已停用!"), false);
        }
    }
}